package com.genghis.ptas.userfriends.service.impl;

import com.genghis.core.page.entity.Page;
import com.genghis.core.page.entity.PageParameter;
import com.genghis.ptas.constant.DictConstant;
import com.genghis.ptas.scorm.entity.ScormInfo;
import com.genghis.ptas.system.service.DictService;
import com.genghis.ptas.userfriends.dao.UserFriendDao;
import com.genghis.ptas.userfriends.entity.UserFriend;
import com.genghis.ptas.userfriends.service.UserFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: yutong
 * Date: 14-4-22
 * Time: 下午8:16
 * To change this template use File | Settings | File Templates.
 */
@Transactional
@Service("userFriendService")
public class UserFriendServiceImpl implements UserFriendService {

    @Autowired
    private UserFriendDao userFriendDao;

    @Autowired
    private DictService dictService;

    @Override
    public void addFriend(UserFriend userFriend) {
           userFriendDao.addFriend(userFriend);
    }

    @Override
    public Page<UserFriend> findFriendPageList(PageParameter pageParameter, UserFriend userFriend) {
        Page<UserFriend> friendPage=userFriendDao.findFriendPageList(pageParameter, userFriend);
        for(UserFriend userFriend1:friendPage.getResultList()){
            userFriend1.setShowSex(dictService.changeDictCodeToValue(userFriend1.getSex(), DictConstant.SEX));
        }
        return friendPage;
    }

    @Override
    public List<String> findFriendId(int id) {

        return userFriendDao.findFriendId(id);
    }

    @Override
    public void delFriendById(int id) {
         userFriendDao.delFriendById(id);
    }

    @Override
    public Page findFriendCoursePageList(PageParameter pageParameter, ScormInfo scormInfo, int userId) {
        Page<ScormInfo> scormInfoPage=userFriendDao.findFriendCoursePage(pageParameter, scormInfo, userId);
        for (ScormInfo scormInfoPage1 : scormInfoPage.getResultList()) {
            scormInfoPage1.setShowCourseType(dictService.changeDictCodeToValue(scormInfoPage1.getCourseType(), DictConstant.COURSE_TYPE));
        }
        return scormInfoPage;
    }


}
